﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class RetailOrderDetailMapping : IEntityTypeConfiguration<RetailOrderDetail>
    {
        public void Configure(EntityTypeBuilder<RetailOrderDetail> builder)
        {
            builder.Property(x => x.EyeType).HasMaxLength(50);
            builder.Property(x => x.DegreesType).HasMaxLength(5);
            builder.Property(x => x.SPH);
            builder.Property(x => x.CYL);
            builder.Property(x => x.ADD).IsRequired(false);
            builder.Property(x => x.Diameter).IsRequired(false);
            builder.Property(x => x.Axis).IsRequired(false);
            builder.Property(x => x.PD).IsRequired(false);
            builder.Property(x => x.PH).IsRequired(false);
            builder.Property(x => x.Base).IsRequired(false).HasMaxLength(5);
            builder.Property(x => x.CenterThickness).IsRequired(false);
            builder.Property(x => x.KnifeSide).IsRequired(false);
            builder.Property(x => x.Decenter1).IsRequired(false).HasMaxLength(8);
            builder.Property(x => x.Decenter2).IsRequired(false);
            builder.Property(x => x.Decenter3).IsRequired(false).HasMaxLength(8);
            builder.Property(x => x.Decenter4).IsRequired(false);
            builder.Property(x => x.Prism1).IsRequired(false).HasMaxLength(8);
            builder.Property(x => x.Prism2).IsRequired(false);
            builder.Property(x => x.Prism3).IsRequired(false).HasMaxLength(8);
            builder.Property(x => x.Prism4).IsRequired(false);
            builder.Property(x => x.Qty);
            //builder.Property(x => x.TaxPrice).HasPrecision(18, 2);
            //builder.Property(x => x.NoTaxPrice).HasPrecision(18, 2);
            //builder.Property(x => x.Price).HasPrecision(18, 2);
            builder.Property(x => x.Discount);

            builder.Property(x => x.RetailOrderId);
            builder.Property(x => x.Contract_LensId);
            builder.Property(x => x.WarehouseId);

            builder.HasOne(x => x.Contract_Lens)
               .WithMany(t => t.RetailOrderDetails)
               .HasForeignKey(m => m.Contract_LensId)
               .OnDelete(DeleteBehavior.NoAction);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.EyeType);
            builder.HasIndex(x => x.RetailOrderId);
            builder.HasIndex(x => x.Contract_LensId);
            builder.Property(x => x.WarehouseId);
        }
    }
}
